#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/StochasticProcess.h>
#pragma unmanaged 
#include <ql\processes\hestonprocess.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Math;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Processes {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IHestonProcess
	public ref class CHestonProcess  : 
            public CStochasticProcess,
            public Cephei::QL::Processes::IHestonProcess
	{
	protected: 
		boost::shared_ptr<QuantLib::HestonProcess>* _ppHestonProcess;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::HestonProcess>* _phHestonProcess;
#endif
		Object^ _HestonProcessOwner;     // reference to object that manages the storage for this object
	internal:
		CHestonProcess (Cephei::QL::Termstructures::IYieldTermStructure^ riskFreeRate, Cephei::QL::Termstructures::IYieldTermStructure^ dividendYield, Cephei::QL::IQuote^ s0, Double v0, Double kappa, Double theta, Double sigma, Double rho, Microsoft::FSharp::Core::FSharpOption<QL::Processes::HestonProcess::DiscretizationEnum>^ d);
        CHestonProcess (boost::shared_ptr<QuantLib::HestonProcess>& childNative, Object^ owner);
        CHestonProcess (QuantLib::HestonProcess& childNative, Object^ owner);
        CHestonProcess (CHestonProcess^ copy);
        CHestonProcess (PLATFORM::Type^ t);
#ifdef STRUCT
        CHestonProcess (QuantLib::HestonProcess childNative);
#endif       
#ifdef HANDLE
		CHestonProcess (QuantLib::Handle<QuantLib::HestonProcess>& childNative, Object^ owner);
		CHestonProcess (QuantLib::Handle<QuantLib::HestonProcess> childNative);
#endif
		virtual ~CHestonProcess ();
		!CHestonProcess ();

	internal:
		QuantLib::HestonProcess& GetReference ();
		boost::shared_ptr<QuantLib::HestonProcess>& GetShared ();
		QuantLib::HestonProcess* GetPointer ();
        void SetHestonProcess (boost::shared_ptr<QuantLib::HestonProcess> native)
        {
            if (_ppHestonProcess != NULL)
                delete _ppHestonProcess;
            _ppHestonProcess = new boost::shared_ptr<QuantLib::HestonProcess> (native);
            SetStochasticProcess (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppHestonProcess));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::HestonProcess>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Termstructures::IYieldTermStructure^ DividendYield 
        {
		    virtual Cephei::QL::Termstructures::IYieldTermStructure^ get () ;
        }
        property Double Kappa 
        {
		    virtual Double get () ;
        }
        property Double Rho 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Termstructures::IYieldTermStructure^ RiskFreeRate 
        {
		    virtual Cephei::QL::Termstructures::IYieldTermStructure^ get () ;
        }
        property Cephei::QL::IQuote^ S0 
        {
		    virtual Cephei::QL::IQuote^ get () ;
        }
        property Double Sigma 
        {
		    virtual Double get () ;
        }
        property UInt64 Size 
        {
		    virtual UInt64 get () ;
        }
        property Double Theta 
        {
		    virtual Double get () ;
        }
		virtual Double Time (DateTime d) ;
        property Double V0 
        {
		    virtual Double get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Processes::IHestonProcess^>::typeid)]
	[FactoryFor(Cephei::QL::Processes::IHestonProcess::typeid)]
	[FactoryFor(Cephei::QL::Processes::IHestonProcess_Factory::typeid)]
	public ref class CHestonProcess_Factory sealed : public IHestonProcess_Factory
	{
	public:
        virtual IHestonProcess^ Create (Cephei::QL::Termstructures::IYieldTermStructure^ riskFreeRate, Cephei::QL::Termstructures::IYieldTermStructure^ dividendYield, Cephei::QL::IQuote^ s0, Double v0, Double kappa, Double theta, Double sigma, Double rho, Microsoft::FSharp::Core::FSharpOption<QL::Processes::HestonProcess::DiscretizationEnum>^ d);
    };
   
/*Cephei*/ } /*QL*/ } /*Processes */}
